#!/bin/bash

# 检查是否提供了.ui文件作为参数
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <ui_file>"
    exit 1
fi

UI_FILE="$1"
HEADER_FILE="${UI_FILE%.ui}.h"

# 检查.ui文件是否存在
if [ ! -f "$UI_FILE" ]; then
    echo "Error: UI file '$UI_FILE' does not exist."
    exit 1
fi

# 获取uic工具的路径
UIC_EXECUTABLE=$(qmake -query QT_INSTALL_BINS)/uic

# 使用uic工具生成.h文件
"$UIC_EXECUTABLE" "$UI_FILE" -o "$HEADER_FILE"

# 检查是否生成成功
if [ $? -eq 0 ]; then
    echo "Header file '$HEADER_FILE' generated successfully."
else
    echo "Failed to generate header file."
fi
